class Solution1 {
    String[] hash = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};//数字和字符串映射
    StringBuffer path;//记录当前路径下的字符串(String操作太复杂，直接用StringBuffer)
    List<String> ret;//返回的结果

    public List<String> letterCombinations(String digits) {
        ret = new ArrayList<>();
        path = new StringBuffer();

        //特判
        if(digits.length()==0) return ret;

        dfs(digits,0);
        return ret;
    }
    public void dfs(String digits,int pos) {
        //递归出口
        if(digits.length()==pos) {
            ret.add(path.toString());
            return;
        }
        String cur = hash[digits.charAt(pos)-'0'];//digits.chatAt(pos)拿到的就是'2'
        for(int i=0;i<cur.length();i++) {
            path.append(cur.charAt(i));
            dfs(digits,pos+1);
            path.deleteCharAt(path.length()-1);//恢复现场
        }
    }
}